package com.edu.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class MyController {

    @RequestMapping("/test01")
    public String test01(@RequestParam String stuId){
        return "forward:/index.jsp";
    }


    @RequestMapping("/test02")
    public String test02(){
        String str = null;
        System.out.println(str.length());
        return "forward:/index.jsp";
    }

//    @ExceptionHandler(Throwable.class)
    public ModelAndView exceptionHandler(){
        ModelAndView mv = new ModelAndView();
        System.out.println("c1");
        mv.addObject("msg","出错啦~");
        mv.setViewName("forward:/error.jsp");
        return mv;
    }


//    @ExceptionHandler(NullPointerException.class)
    public ModelAndView exceptionHandler2(){
        ModelAndView mv = new ModelAndView();
        mv.addObject("msg","低级错误，空指针异常");
        mv.setViewName("forward:/error.jsp");
        return mv;
    }
}
